﻿using IdentityModel.Client;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Http.Client.Authentication;

namespace Ebusiness_WebSites.Token
{
    /// <summary>
    /// 动态客户端代理  HttpClient
    /// </summary>
    [Dependency(ServiceLifetime.Singleton)]
    public class TokenRemoteServiceHttpClientAuthenticator : IRemoteServiceHttpClientAuthenticator
    {
        /// <summary>
        /// 传递token方法
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task Authenticate(RemoteServiceHttpClientAuthenticateContext context)
        {
            //1、实现传递token
            HttpClient httpClient = context.Client;

            // 2、获取token

            // 3、传递token (本质：都是请求头)
            httpClient.SetBearerToken(TokenSave.Token);

            return Task.CompletedTask;
        }
    }
}
